import logging
from logging.handlers import RotatingFileHandler

from app.config.config import config
from app.settings import env

# 增加日志的配置
def set_log():
    config_class = config[env]
    # 设置日志的等级
    logging.basicConfig(level=config_class.LOG_LEVEL)
    # 创建日志记录器,指定报错日志路径,每个日志文件最大容量,保存日志的个数
    file_log_handler = RotatingFileHandler("log/echoscript.log",maxBytes=1024*1024*300,backupCount=10)
    # 创建日子记录的格式
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(lineno)d - %(message)s')
    file_log_handler.setFormatter(formatter)
    # 为全局日志工具对象添加日志记录器
    logging.getLogger().addHandler(file_log_handler)

set_log()